package com.wf.imgshow.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.wf.common.util.HTTPClientIPUtil;
import com.wf.common.util.HttpRequest;
import com.wf.imgshow.util.ImgShowUtil;
import com.wf.log.service.LogService;

@Controller
@RequestMapping(value="img")
public class ImgShowController {
	@Autowired
	private LogService logService;
	/**
	 * 好图看看首页
	 * 作者:王锋
	 * 时间:2017年12月7日
	 * @throws IOException 
	 * 首页类型1我的博客首页2,好看图图首页
	 */
	@RequestMapping(value="/imgShow",method=RequestMethod.GET)
	public String imgShowIndex(HttpServletRequest request,ModelMap map) throws IOException{
		List<String> imgShowList=new ArrayList<String>();
		String ip=HTTPClientIPUtil.getIP(request);
		logService.addArticleInfo(ip,HttpRequest.getIpRegion(ip),2);
		//随机显示页数
		Random ra =new Random();
		int page=ra.nextInt(1000)+1;
		String allHtml=ImgShowUtil.getHtml("https://www.dbmeinv.com/dbgroup/show.htm?cid=4&pager_offset="+page);
		imgShowList=ImgShowUtil.getImgStr(allHtml);
		map.put("imgShowList", imgShowList);
		map.put("page", page);
		return "/imgShow/imgShowIndex";
	}
	
	/**
	 * 你懂的
	 * 作者:王锋
	 * 时间:2017年12月8日
	 */
	@RequestMapping(value="/imgShow4SW",method=RequestMethod.GET)
	public String imgShowSiWaAndPP(HttpServletRequest request,ModelMap map){
		List<String> imgShowList=new ArrayList<String>();
		//记录日志
		String ip=HTTPClientIPUtil.getIP(request);
		logService.addArticleInfo(ip,HttpRequest.getIpRegion(ip),2);
		//这里固定显示第一页
		String allHtml=ImgShowUtil.getHtml("https://www.dbmeinv.com/dbgroup/show.htm?cid=6&pager_offset=1");
		String allHtmlDX=ImgShowUtil.getHtml("https://www.dbmeinv.com/dbgroup/show.htm?cid=2&pager_offset=1");
		imgShowList=ImgShowUtil.getImgStr(allHtml+allHtmlDX);
		map.put("imgShowList", imgShowList);
		return "/imgShow/imgShowMMIndex";
	}
	
		public static void main(String[] args) {
			String str="\u4e2d\u56fd";
			System.out.println(str);
		
		}
	
}
